#include "common/unp.h"

int main( int argc, char ** argv)
{
	int listenfd, connfd;
	struct sockaddr_in servaddr;
	char buff[MAXLINE];
	time_t ticks;
	listenfd = socket( AF_INET, SOCK_STREAM, 0 );
	if( listenfd < 0 ){
		printf("create listenfd socket failed \n");
	}
	memset( &servaddr, 0, sizeof(servaddr) );
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(3113);
	bind( listenfd, (struct sockaddr*)&servaddr, sizeof(servaddr) );
	listen( listenfd, 10 );
	while(1)
	{
		connfd = accept( listenfd, (struct sockaddr*)NULL, NULL );
		ticks = time(NULL);
		snprintf( buff, sizeof(buff), "%.24s \r\n", ctime(&ticks) );
		write(connfd, buff, strlen(buff) );
		close( connfd );
	}
}
